﻿using Admin.DAL;
using Admin.Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Admin.Controllers
{
    public class Floor3AdminController : Controller
    {
        //
        // GET: /FloorAdmin/
        public ActionResult Index()
        {
            return View();
        }
        //show
        public ActionResult Floor3(string id)
        {
            Floor3AdminDAL pro = new Floor3AdminDAL();
            List<FloorAdminModel> list = pro.Floor3(id);


            return View(list);
        }
        //insert
        [HttpGet]
        public ActionResult insertFloor3(string id)
        {

            return View();
        }
        [HttpPost]
        public ActionResult insertFloor3(FloorAdminModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var asd = new FloorAdminModel();
                    List<FloorAdminModel> list = new List<FloorAdminModel>();
                    SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=LazadaDB;User ID=sa;Password=sa");
                    conn.Open();
                    SqlCommand command = new SqlCommand("insert into T3 (Name) Values(N'" + model.NAME + "')", conn);
                    SqlDataReader dr = command.ExecuteReader();
                    return RedirectToAction("Floor3");

                }
                return View(model);

            }
            catch
            {
                return View();
            }

        }
        //DELETE
        public ActionResult deleteFloor3(string id)
        {
            Floor3AdminDAL dal = new Floor3AdminDAL();
            List<FloorAdminModel> list = dal.deleteF3(id);
            return View(list);
        }

        [HttpPost, ActionName("DeleteFloor3")]
        [ValidateAntiForgeryToken]

        public ActionResult Delete(string id)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=LazadaDB;User ID=sa;Password=sa");
            conn.Open();
            SqlCommand cmd = new SqlCommand("delete from T3 where ID='" + id + "'", conn);
            cmd.ExecuteNonQuery();
            return RedirectToAction("Floor3");
        }
        //edit
        [HttpGet]
        public ActionResult editFloor3(string id)
        {

            Floor3AdminDAL dal = new Floor3AdminDAL();
            List<FloorAdminModel> list = dal.editF3(id);
            return View(list);
        }

        [HttpPost]
        public ActionResult Edit(string id, FloorAdminModel model, FormCollection collection)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=LazadaDB;User ID=sa;Password=sa");
            conn.Open();
            model.NAME = collection["tennhomsp"];
            SqlCommand cmd = new SqlCommand("Update T3 set Name=N'"+model.NAME+"' where Id='"+id+"'", conn);
            cmd.ExecuteReader();
            

            return RedirectToAction("Floor3");
        }
       
	}
}